package com.tju.t5.action.user;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.tju.t5.entity.User;
import com.tju.t5.service.IUserService;

public class UserAction {
	
	/*
	 * static Fields
	 */
	
	
	private IUserService userService;
	private User user;

	public IUserService getUserService() {
		return userService;
	}

	public void setUserService(IUserService userService) {
		this.userService = userService;
	}
	
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String forgetPassword()
	{
		return "failure";
	}
	
	public String login()
	{
		User userInfo = userService.getUserByUsername(user.getUsername());
		
		if(userInfo == null)
		{
			return "user_not_exists";
		}
		else
		{
			if(userInfo.getPassword().equals(user.getPassword()))
			{
				Map<String, Object> session = ActionContext.getContext().getSession();
				session.put("username", userInfo.getUsername());
				session.put("role", userInfo.getRole());
				return "login_success";
			}
			else
			{
				return "login_failure";
			}
		}
	}
	
	public String logout()
	{
		return "failure";
	}

}
